// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const workshopRequest = {
    // dict请求的基本url
    BASE_URL: confing.MD_URL + "/workshop",
    /**
     * 删除字典
     * @param {*} dictId 
     * @param {*} callback 
     */
    delete(workshopId,callback){
        let url = this.BASE_URL + "/delete?workshopId=" + workshopId;
        request.delete(url,callback);
    },
    /**
     * 批量删除字典
     * @param {*} dictIds 
     * @param {*} callback 
     */
    deletes(workshopIds,callback){
        let url = this.BASE_URL + "/deletes?t=1";
        workshopIds.forEach(element => {
            url += "&workshopId=" + element;
        });
        request.delete(url,callback)
    },
    edit(mdWorkShop,callback){
        console.log(mdWorkShop);
        let url = this.BASE_URL + "/update";
        if(mdWorkShop != undefined && mdWorkShop.workshopId != undefined){
            request.put(url,mdWorkShop,callback)
        }
    },
    selectById(workshopId,callback){
        if(workshopId){
            // 准备url
            let url = this.BASE_URL + "/get?workshopId=" + workshopId;
            request.get(url,callback);
        }
        // 如果没有userId，不做任何处理
    },
    genWorkOrderId(callback) {
        let url = this.BASE_URL + "/generateWorkShopCode"
        request.get(url, callback);
    },
    /**
     * 保存字典信息
     * @param {*} item 
     * @param {*} callback 
     */
    save(mdWorkShop, callback) {
        if (mdWorkShop) {
            request.post(this.BASE_URL + "/save", mdWorkShop, callback);
        }
    },
    // 请求的API
    list(page = 1, limit = 10, mdWorkShop, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if (mdWorkShop) {
            
            if (mdWorkShop.workshopCode) {
                url += "&workshopCode=" + mdWorkShop.workshopCode;
            }
            if (mdWorkShop.workshopName) {
                url += "&workshopName=" + mdWorkShop.workshopName;
            }
        }
        // 发送请求
        request.get(url, callbcak);
    }
}

// 将dictRequest暴漏出去
export default workshopRequest;